<template>
	<view class="flowBefore-v">
		<view v-if="Length" style="display: flex; justify-content: center">
			{{ Index + 1 }}/{{ Length }}
		</view>
		<view class="flowBefore-box" v-if="config.opType === '-1'">
			<view class="scroll-v" scroll-y>
				<childForm ref="child" :config="config" @eventReceiver="eventReceiver" :companyName='companyName' />
				<candidate-form v-model="selectShow" :candidateList="candidateList" :taskId="config.taskId"
					:formData="formData" @submitCandidate="submitCandidate" ref="candidateForm" />
			</view>
		</view>
		<view class="flowBefore-box" v-else>
			<view class="u-border-bottom">
				<u-sticky>
					<u-tabs :list="tabBars" :is-scroll="true" :current="tabIndex" @change="tabChange" height="100">
					</u-tabs>
				</u-sticky>
			</view>
			<block>
				<view v-show="tabsName === '表单信息'">
					<view>
						<view class="flowStatus" v-if="config.opType == 0 || config.opType == 4">
							<image :src="flowStatus" mode="widthFix"></image>
						</view>
						<childForm ref="child" :config="config" @eventReceiver="eventReceiver" @setBtnLoad="setBtnLoad"
							:companyName='companyName' />
						<candidate-form v-model="selectShow" :candidateList="candidateList" :taskId="config.taskId"
							:formData="formData" @submitCandidate="submitCandidate" ref="candidateForm" />
					</view>
				</view>
				<view class="nodeList-v" v-if="tabsName === '流程信息'">
					<steps :options="flowTaskNodeList" />
				</view>
				<view class="record-v" v-if="tabsName === '流转记录'">
					<records :options="recordList" :endTime="endTime" />
				</view>
				<view class="record2-v" v-if="tabsName === '审批汇总'">
					<RecordSummary :processId="processId" ref="recordSummary" :summaryType="summaryType">
					</RecordSummary>
				</view>
				<view v-if="tabsName === '流程评论'">
					<view class="record-v">
						<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
							:sticky="false" :down="downOption" :up="upOption" :bottombar="false">
							<view class="discuss_box">
								<scroll-view scroll-y="true" style="height: 100%">
									<view class="u-flex-col discuss_list" v-for="(item, index) in commentList"
										:key="index">
										<view class="u-flex discuss_txt">
											<view class="discuss_txt_left u-flex">
												<u-avatar :src="baseURL + item.creatorUserHeadIcon"></u-avatar>
												<text class="uName">{{ item.creatorUserName }}</text>
											</view>
											<text v-if="item.isDel" class="del"
												@click.stop="delComment(item.id, index)">删除</text>
										</view>
										<view class="u-flex-col discuss_content">
											<text class="txt">{{ item.text }}</text>
											<view class="u-flex img_box" v-if="item.image.length">
												<jnpf-upload v-model="item.image" :disabled="true" />
											</view>
											<jnpf-file v-model="item.file" :show="false" :disabled="true"
												v-if="item.file.length" />
										</view>
										<view style="padding-left: 110rpx; margin-top: 20rpx">
											<text>{{
                        $u.timeFormat(item.creatorTime, "yyyy-mm-dd hh:MM")
                      }}</text>
										</view>
									</view>
								</scroll-view>
							</view>
						</mescroll-body>
					</view>
					<view class="discuss_btn" v-if="tabsName === '流程评论'">
						<button @click.stop="jumpComment" class="custom-style">评论</button>
					</view>
				</view>
			</block>
		</view>

		<view class="flowBefore-actions" v-if="tabIndex != 4 && tabIndex != 3">
			<!-- 新增流程 -->
			<template v-if="config.addStatus ===true">
				<!-- 	<u-button class="buttom-btn" @click.stop="eventLauncherSave('save')" :loading="btnLoading">
					{{ properties.saveBtnText || "暂存" }}
				</u-button> -->
				<u-button class="buttom-btn" type="primary" @click.stop="eventLauncherSubmit('submit')">
					{{ properties.submitBtnText || "提交" }}
				</u-button>
			</template>
			<template v-if="
          (config.type === 1 &&
            (config.jurisdictionType === 'btn_edit' ||
              config.jurisdictionType === 'btn_add') &&
            config.opType == '-1') ||
          (config.type !== 1 && config.opType == '-1')
        ">
				<u-button class="buttom-btn" @click.stop="eventLauncher('save')" :loading="btnLoading">
					{{ properties.saveBtnText || "暂存" }}
				</u-button>
				<u-button class="buttom-btn" type="primary" @click.stop="eventLauncher('audit')">
					{{ properties.submitBtnText || "提交" }}
				</u-button>
			</template>
			<template v-if="config.opType == '-1'">
				<!-- 审核驳回显示的按钮 -->
				<template v-if="config.status == 3||config.status == 4">
					<u-button class="buttom-btn" @click.stop="eventLauncher('save')" :loading="btnLoading">
						{{ properties.saveBtnText || "暂存" }}
					</u-button>
					<u-button class="buttom-btn" type="primary" @click.stop="eventLauncher('submit')">
						{{ properties.submitBtnText || "提交" }}
					</u-button>
				</template>
			</template>
			<!--我发起的详情显示的按钮  -->
			<template v-if="config.opType == 0">
				<!-- 等待审核显示的按钮 -->
				<template v-if="config.status == 1">
					<u-button class="buttom-btn" type="primary" @click.stop="handlePress()" v-if="
              properties.hasPressBtn || properties.hasPressBtn === undefined
            ">
						{{ properties.pressBtnText || "催办" }}
					</u-button>
					<u-button class="buttom-btn" type="error" @click.stop="operate('revoke', '撤回')" v-if="
              properties.hasRevokeBtn || properties.hasRevokeBtn === undefined
            ">
						{{ properties.revokeBtnText || "撤回" }}
					</u-button>
				</template>
				<!-- 审核驳回显示的按钮 -->
				<template v-else-if="config.status == 3">
					<u-button class="buttom-btn" @click.stop="eventLauncher('save')" :loading="btnLoading">
						{{ properties.saveBtnText || "暂存" }}
					</u-button>
					<u-button class="buttom-btn" type="primary" @click.stop="eventLauncher('submit')">
						{{ properties.submitBtnText || "提交" }}
					</u-button>
				</template>
				<u-button class="buttom-btn" @click.stop="jnpf.goBack()" v-else>返回</u-button>
			</template>
			<!-- 待办事宜显示的按钮 -->
			<template v-if="config.opType == 1">
				<u-button class="buttom-btn" type="warning" @click.stop="openUserBox('transfer')"
					v-if="properties.hasTransferBtn">
					{{ properties.transferBtnText || "转审" }}
				</u-button>
				<u-button class="buttom-btn" type="primary" v-if="properties.hasAuditBtn"
					@click.stop="eventLauncher('audit')">
					{{ properties.auditBtnText || "通过" }}
				</u-button>
				<u-button class="buttom-btn" type="error" v-if="properties.hasRejectBtn"
					@click.stop="eventReceiver({}, 'reject')">
					{{ properties.rejectBtnText || "拒绝" }}
				</u-button>
				<u-button class="buttom-btn" type="save" v-if="properties.hasSaveBtn"
					@click.stop="eventLauncher('saveAudit')">
					{{ properties.saveBtnText || "暂存" }}
				</u-button>
			</template>
			<u-button class="buttom-btn" type="error" v-if="config.opType == 2 && properties.hasRevokeBtn"
				@click.stop="operate('recall', properties.revokeBtnText)">
				{{ properties.revokeBtnText || "撤回" }}555
			</u-button>
			<u-button class="buttom-btn" @click.stop="jnpf.goBack()" v-if="config.opType == 3">返回</u-button>
		</view>
		<userSelect v-model="userSelectShow" @confirm="selectConfirm"></userSelect>
	</view>
</template>

<script>
	import {
		Create,
		Update,
		DynamicCreate,
		DynamicUpdate,
	} from "@/api/workFlow/workFlowForm";
	import {
		FlowBeforeInfo,
		Audit,
		Reject,
		Transfer,
		Recall,
		Cancel,
		SaveAudit,
		Candidates,
		getInfo,
	} from "@/api/workFlow/flowBefore";
	import {
		Revoke,
		Press
	} from "@/api/workFlow/flowLaunch";
	import {
		getCommentList,
		createComment,
		delComment,
		FlowEngineInfo,
		getFlowInfo,
	} from "@/api/workFlow/flowEngine";
	import resources from "@/libs/resources.js";
	import userSelect from "@/components/jnpf/jnpf-user-select/user-tree.vue";
	import childForm from "./form.vue";
	import steps from "../components/steps.vue";
	import records from "../components/records.vue";
	import CandidateForm from "../components/CandidateForm";
	import RecordSummary from "../components/RecordSummary";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import define from "@/utils/define.js"
	export default {
		mixins: [MescrollMixin],
		components: {
			CandidateForm,
			userSelect,
			childForm,
			steps,
			records,
			RecordSummary,
		},
		data() {
			return {
				downOption: {
					use: true,
					auto: true,
				},
				upOption: {
					page: {
						num: 0,
						size: 20,
						time: null,
					},
					empty: {
						use: true,
						icon: resources.message.nodata,
						tip: "暂无数据",
						fixed: true,
						top: "300rpx",
					},
					textNoMore: "没有更多数据",
				},
				isComment: false,
				show: false,
				config: {},
				companyName: define.companyName,
				currentView: "",
				formData: {},
				flowTaskInfo: {},
				flowTaskNodeList: [],
				recordList: [],
				properties: {},
				endTime: 0,
				tabIndex: 0,
				tabBars: [{
						name: "表单信息",
						id: 0,
					},
					{
						name: "流程信息",
						id: 1,
					},
					{
						name: "流转记录",
						id: 2,
					},
				],
				flowStatus: "",
				stepIndex: 0,
				userSelectShow: false,
				userOptions: [],
				btnLoading: false,
				eventType: "",
				commentList: [],
				processId: "",
				selectShow: false,
				candidateList: [],
				isSummary: false,
				summaryType: 0,
				tabsName: "表单信息",
				title: "",
				purtbList: [],
				comList: [], //传过来的数据
				Length: null, //传过来的数据长度
				Index: null, //当前节点下标
				Object: {}, //当前节点
				nextObjectIndex: null, //下一个节点下标
				nextObject: null, //下一个节点数据
				LastStatus: 0,

				// 传给费用的id值

			};
		},
		computed: {
			baseURL() {
				return this.define.baseURL;
			},
		},
		watch: {
			isSummary(val) {
				if (val)
					return this.tabBars.push({
						name: "审批汇总",
						id: 3,
					});
			},
			isComment(val) {
				if (val)
					return this.tabBars.push({
						name: "流程评论",
						id: 4,
					});
			},
		},
		onLoad(option) {
			console.log('option', option);
			uni.showLoading({
				title: "加载中",
			});
			const complexObjectStr = uni.getStorageSync('complexObject');
			const complexObject = JSON.parse(complexObjectStr);
			let config = complexObject
			if (!config) return this.jnpf.goBack();
			this.config = config;
			this.init();
			// uni.$on("operate", (data) => {
			// 	console.log("operatedata", data);
			// 	this[data.eventType + "Handle"](data);
			// });
			uni.$on("comment", (data) => {
				this.commentList = [];
				this.current = 0;
				this.addComment(data);
			});
			this.processId = this.config.id;
		},
		onShow() {
			uni.$on("operate", (data) => {
				console.log("operatedata", data);
				this[data.eventType + "Handle"](data);
			});
		},
		onUnload() {
			uni.removeStorageSync('complexObject')
			uni.$off("operate");
			uni.$off("refresh");
			uni.$off("comment");
		},
		methods: {
			// 保存
			eventLauncherSave(eventType) {
				console.log("  保存");
				this.$refs.child.$refs.form.$refs.addFormRef.selfSubmit(eventType);
			},
			// 提交
			eventLauncherSubmit(eventType) {
				console.log(" 提交");
				this.$refs.child.$refs.form.$refs.addFormRef.selfSubmit(eventType);
			},

			upCallback(page) {
				let query = {
					currentPage: page.num,
					pageSize: page.size,
					sort: "desc",
					sidx: "",
					taskId: this.processId,
				};
				getCommentList(query, {
						load: page.num == 1,
					})
					.then((res) => {
						this.mescroll.endSuccess(res.data.list.length);
						if (page.num == 1) this.commentList = [];
						const list = res.data.list.map((o) => {
							o.image = JSON.parse(o.image);
							o.file = JSON.parse(o.file);
							return o;
						});
						this.commentList = this.commentList.concat(list);
					})
					.catch(() => {
						this.mescroll.endErr();
					});
			},
			tabChange(index) {
				this.tabIndex = index;
				this.tabsName = this.tabBars[index].name;
				// if (this.tabsName === '流程评论') this.mescroll.resetUpScroll();
			},
			jumpComment() {
				uni.navigateTo({
					url: "/pages/workFlow/comment/index",
				});
			},
			addComment(query) {
				query.taskId = this.processId;
				createComment(query).then((res) => {
					this.mescroll.resetUpScroll();
				});
			},
			delComment(id, i) {
				uni.showModal({
					title: "提示",
					content: "确定删除?",
					success: (res) => {
						if (res.confirm) {
							delComment(id).then((res) => {
								this.commentList.splice(i, 1);
								this.mescroll.resetUpScroll();
							});
						}
					},
				});
			},
			init() {
				this.tabIndex = 0;
				/**
				 * opType
				 * -1 - 我发起的新建/编辑
				 * 0 - 我发起的详情
				 * 1 - 待办事宜
				 * 2 - 已办事宜
				 * 3 - 抄送事宜
				 */
				if (this.config.opType == "-1") {
					console.log('this.config-1', this.config);
					this.getEngineInfo(this.config);
				} else {
					console.log('this.config2', this.config);
					this.getBeforeInfo(this.config);
					let resData = this.findObjectInfo(
						this.config.clickObj,
						this.config.itemList
					);
					this.comList = this.config.itemList; //原始数组
					this.Length = this.config.itemList.length; //数组长度
					this.Index = resData.currentObjectIndex; //当前下标
					this.Object = resData.currentObject; //当前对象
					this.nextObjectIndex = resData.nextObjectIndex; //下一个对象下标
					this.nextObject = resData.nextObject; //下一个对象
				}
			},
			// 获取下一个对象的信息
			findObjectInfo(targetObject, List) {
				let targetIndex = List.findIndex(
					(obj) => obj.thisStepId === targetObject.thisStepId
				);
				let nextObject = List[targetIndex + 1];
				let nextIndex = targetIndex + 1;
				return {
					currentObject: targetObject,
					currentObjectIndex: targetIndex,
					nextObject: nextObject == undefined ? "为空" : nextObject,
					nextObjectIndex: nextIndex,
				};
			},
			getFlowInfoList(data) {
				getFlowInfo(data.id).then((res) => {
					if (res.code == 200) {
						this.purtbList = res.data.purtbList;
					}
				});
			},
			getEngineInfo(data) {
				FlowEngineInfo(data.flowId).then((res) => {
					console.log('this.config-1===>res', res);
					this.title = res.data.fullName;
					uni.setNavigationBarTitle({
						title: this.title,
					});
					data.type = res.data.type;
					data.formConf = res.data.formData;
					const flowTemplateJson = res.data.flowTemplateJson ?
						JSON.parse(res.data.flowTemplateJson) :
						null;
					this.flowTemplateJson = flowTemplateJson;
					data.formOperates = [];
					this.properties =
						(this.flowTemplateJson && this.flowTemplateJson.properties) || {};
					if (
						flowTemplateJson &&
						flowTemplateJson.properties &&
						flowTemplateJson.properties.formOperates
					) {
						data.formOperates = flowTemplateJson.properties.formOperates || [];
					}
					console.log('全部流程进来的新增', this.config.addStatus);
					setTimeout(() => {
						this.$refs.child.$refs.form.init(data, this.config.id, flowTemplateJson,
							this.config.addStatus);
					}, 100);
				});
				uni.hideLoading();
			},
			getBeforeInfo(data) {
				this.formData.flowId = data.flowId;
				FlowBeforeInfo(data.id, {
					taskNodeId: data.taskNodeId,
					taskOperatorId: data.taskId,
				}).then((res) => {
					uni.hideLoading();
					this.flowTaskInfo = res.data.flowTaskInfo;
					this.config.status = this.flowTaskInfo.status;
					this.config.fullName = this.flowTaskInfo.fullName;
					this.title = this.flowTaskInfo.fullName;
					if (this.config.status !== 0 && this.config.status !== 3) {
						this.title = this.flowTaskInfo.thisStep ?
							this.config.fullName + "/" + this.flowTaskInfo.thisStep :
							this.config.fullName;
					}
					uni.setNavigationBarTitle({
						title: this.title,
					});
					this.flowTaskNodeList = res.data.flowTaskNodeList;
					const recordList = res.data.flowTaskOperatorRecordList || [];
					this.recordList = recordList.reverse();
					this.properties = res.data.approversProperties || {};
					this.endTime =
						this.flowTaskInfo.completion == 100 ? this.flowTaskInfo.endTime : 0;
					data.type = this.flowTaskInfo.type;
					data.draftData = res.data.draftData || null;
					const flowTemplateJson = this.flowTaskInfo.flowTemplateJson ?
						JSON.parse(this.flowTaskInfo.flowTemplateJson) :
						null;
					const flowFormContentJson = this.flowTaskInfo.flowFormContentJson ?
						JSON.parse(this.flowTaskInfo.flowFormContentJson) :
						null;
					this.flowTemplateJson = flowTemplateJson;
					this.isComment = this.flowTemplateJson.properties.isComment;
					this.isSummary = this.flowTemplateJson.properties.isSummary;
					this.summaryType = this.flowTemplateJson.properties.summaryType;
					this.endTime =
						this.flowTaskInfo.completion == 100 ? this.flowTaskInfo.endTime : 0;
					data.formConf = res.data.flowFormInfo;
					if (data.opType != 1) data.readonly = true;
					if (data.opType == 0 && data.status == 3) data.readonly = false;
					data.formOperates = [];
					if (data.opType == 0) {
						this.properties =
							(this.flowTemplateJson && this.flowTemplateJson.properties) || {};
						if (
							flowTemplateJson &&
							flowTemplateJson.properties &&
							flowTemplateJson.properties.formOperates
						) {
							data.formOperates = flowTemplateJson.properties.formOperates || [];
						}
					} else {
						data.formOperates = res.data.formOperates || [];
					}
					/**
					 * status
					 * 0 等待提交
					 * 1 等待审核
					 * 2 审核通过
					 * 3 审核驳回
					 * 4 流程撤回
					 * 5 审核终止 
					 */
					switch (this.config.status) {
						case 0: //等待提交
							this.flowStatus = resources.status.submit;
							break;
						case 1: //等待审核
							this.flowStatus = resources.status.review;
							break;
						case 2: //审核通过
							this.flowStatus = resources.status.reviewAdopt;
							break;
						case 3: //审核驳回
							this.flowStatus = resources.status.reviewRefuse;
							break;
						case 4: //流程撤回
							this.flowStatus = resources.status.reviewUndo;
							break;
						case 5: //审核终止
							this.flowStatus = resources.status.reviewStop;
							break;
						default: //等待审核
							this.flowStatus = resources.status.review;
							break;
					}

					setTimeout(() => {
						const relevantCodes = [
							"PURTAFlow",
							"ASTTIFlow",
							"MOCTAFlow",
							"ASTTMFlow",
							"ASTTM",
							"PURTEFlow",
							"PURTLFlow",
							"MOCI10_Flow",
							"PURTCFLOW",
							"PURTC",
							"YYDPURMA",
							"COPMEFlow",
							"INVTA",
							"COPTCflow",
							"COPTA01",
							"APSTA",
							"advancePaymentWithFlow",
							"ASTTO",
							"COPTA",
							"COPTI",
							"BPMPURAA",
							"BPMGURAA",
							"Pjswa",
							"PJSTA_ZZ",
							"pjstnD",
							"psjtbD",
							"PJSXZ",
							"PJSYF",
							"PJSXX",
							"MOCTH",
							"PURTG",
							"PJSYB",
							"PJSYO",
							"PJSYJ",
							"PJSYQ",
							"PJSZU",
							"PJSZX",
							"PJSZZ",
							"PJTAH",
							"PJTAI",
							"PJSXC",
							"PJSWC",
							"PJSWH",
							"PJSXD",
							"PJSXI",
							"ASTTI",
							"PURTA",
							"PJSXM",
							"PJSXV",
							"PJSXT",
							"PJSXR",
							"PJSWK",
							"PJSWP",
							"PJSWX",
							"PJTAJ",
							"PJSWV",
							"PJSWZ",
							"PJSWY",
							"BOMCA_ZZ",
							"BOMTA",
							"BOMCAFlow",
							"COPUA",
							"OASTE",
							"OASTG",
							"OASTA",
							"OASTI",
							"OASTL",
							"COPTG",
						];
						if (relevantCodes.includes(this.config.enCode)) {
							console.log('this.$refs.child', this.$refs.child.$refs.formCom);
							// this.$refs.child.$refs.formCom.$refs.form.init(
							// 	data,
							// 	this.config.id,
							// 	flowFormContentJson
							// );
							// this.$refs.child.$refs.formCom.$refs.form.initDataForm(flowFormContentJson);

							this.$refs.child.$refs.form.init(
								data,
								this.config.id,
								flowFormContentJson
							);
							this.$refs.child.$refs.form.initDataForm(flowFormContentJson);
						} else {
							uni.showToast({
								title: "暂无此流程表单",
								icon: "none",
								complete: () => {
									setTimeout(() => {
										uni.navigateBack();
									}, 1500);
								},
							});
							return;
						}
					}, 100);
				});
			},
			eventLauncher(eventType) {
				console.log('eventType报价管理', eventType);
				this.$refs.child &&
					this.$refs.child.$refs.form &&
					this.$refs.child.$refs.form.submit(eventType, this.config);
			},
			eventReceiver(formData, eventType) {
				this.formData = formData;
				this.eventType = eventType;
				const eventActions = {
					save: () => this.submitOrSave("save"),
					submit: () => this.submitOrSave("submit"),
					saveAudit: () => this.saveAudit(),
					audit: () => this.operate("audit", this.properties?.auditBtnText),
					reject: () => this.operate("reject", this.properties?.rejectBtnText),
				};
				// 使用?.操作符来安全地访问属性，防止undefined错误
				const action = eventActions[eventType];
				return action ? action() : null; // 如果没有找到对应的操作，则返回null
			},
			/* 保存草稿 */
			saveAudit() {
				this.btnLoading = true;
				let query = {
					formData: this.formData,
				};
				SaveAudit(this.config.taskId, query)
					.then((res) => {
						uni.showToast({
							title: res.msg,
							complete: () => {
								setTimeout(() => {
									this.btnLoading = false;
									uni.navigateBack();
								}, 1500);
							},
						});
					})
					.catch(() => {
						this.btnLoading = false;
					});
			},
			// 候选人提交
			submitCandidate(data) {
				this.selectShow = false;
				if (data) {
					this.handleRequest(data);
				} else {
					uni.showModal({
						title: "提示",
						content: "您确定要提交当前流程吗？",
						success: (res) => {
							this.handleRequest();
						},
					});
				}
			},
			submitOrSave(eventType) {
				this.formData.status = eventType === "submit" ? 0 : 1;
				if (eventType === "save") return this.handleRequest();
				Candidates(0, {
						formData: this.formData,
					})
					.then((res) => {
						let data = res.data;
						if (Array.isArray(data) && data.length) {
							this.candidateList = res.data;
							this.selectShow = true;
						} else {
							uni.showModal({
								title: "提示",
								content: "您确定要提交当前流程吗？",
								success: (res) => {
									if (res.confirm) {
										this.handleRequest();
									}
								},
							});
						}
					})
					.catch(() => {
						this.selectShow = false;
					});
			},
			// 转审提交事件
			selectConfirm(e) {
				const ids = e.map((o) => o.id);
				const id = ids.join();
				if (this.eventType === "transfer") return this.handleTransfer(id);
			},
			// 转审提交按钮
			handleTransfer(freeApproverUserId) {
				if (this.Length === 1) {
					Transfer(this.config.taskId, {
						freeApproverUserId,
					}).then((res) => {
						// this.toastAndBack(res.msg, true)
						uni.switchTab({
							url: "/pages/index/workFlow",
						});
					});
				} else {
					Transfer(this.config.taskId, {
						freeApproverUserId,
					}).then((res) => {
						uni.showToast({
							title: res.msg,
						});
						let data = this.findObjectInfo(this.nextObject, this.comList);
						this.Object = data.currentObject;
						this.Index = data.currentObjectIndex;
						this.nextObjectIndex = data.nextObjectIndex;
						this.nextObject = data.nextObject;
						this.config.taskId = this.Object.taskId;
						if (data.nextObject == "为空") {
							this.nextObject = this.Object;
							this.LastStatus++;
							if (this.LastStatus > 1) {
								setTimeout(() => {
									// uni.navigateBack()
									uni.switchTab({
										url: "/pages/index/workFlow",
									});
								}, 1500);
								this.LastStatus = 0;
								return;
							}
						}
						this.config = {
							flowId: this.Object.flowId,
							formType: this.Object.formType,
							status: this.Object.status,
							fullName: this.Object.fullName,
							id: this.Object.processId,
							taskNodeId: this.Object.thisStepId,
							taskId: this.Object.id,
							opType: 1,
							enCode: this.Object.flowCode,
						};
						this.getBeforeInfo(this.config);
					});
				}
			},
			handleRequest(candidateList) {
				if (candidateList) this.formData.candidateList = candidateList;
				if (this.eventType === "save") this.btnLoading = true;
				let formMethod = null;
				if (this.config.formType == 1) {
					formMethod = this.formData.id ? Update : Create;
				} else {
					formMethod = this.formData.id ? DynamicUpdate : DynamicCreate;
				}
				formMethod(this.config.enCode, this.formData)
					.then((res) => {
						uni.showToast({
							title: res.msg,
							complete: () => {
								setTimeout(() => {
									if (this.formData.id) uni.$emit("refresh");
									this.btnLoading = false;
									uni.navigateBack();
								}, 1500);
							},
						});
					})
					.catch(() => {
						this.btnLoading = false;
					});
			},
			handlePress() {
				uni.showModal({
					title: "提示",
					content: "此操作将提示该节点尽快处理",
					success: (res) => {
						if (res.confirm) {
							Press(this.config.id).then((res) => {
								this.$u.toast(res.msg);
							});
						}
					},
				});
			},
			openUserBox(eventType) {
				this.userSelectShow = true;
				this.eventType = eventType;
			},
			operate(eventType, title) {
				let config = {
					eventType,
					title: "确认" + title.replace(/\s+/g, ""),
				};
				if (eventType === "audit" || eventType === "reject") {
					config = {
						...config,
						hasSign: this.properties.hasSign,
						hasFreeApprover: this.properties.hasFreeApprover,
						isCustomCopy: this.properties.isCustomCopy,
						formData: this.formData,
						taskId: this.config.taskId,
						eventType: eventType,
						flowId: this.config.flowId,
					};
					console.log("通过或者拒绝的config=>", config);
				}
				uni.navigateTo({
					url: "/pages/workFlow/operate/index?config=" +
						encodeURIComponent(JSON.stringify(config)),
				});
			},
			// 撤回提交按钮
			revokeHandle(data) {
				Revoke(this.config.id, {
					handleOpinion: data.handleOpinion,
				}).then((res) => {
					this.toastAndBack(res.msg, true);
				});
			},
			recallHandle(data) {
				Recall(this.config.taskId, {
					handleOpinion: data.handleOpinion,
				}).then((res) => {
					this.toastAndBack(res.msg, true);
				});
			},
			// 修改
			auditHandle(data) {
				this.handleApproval(data);
			},
			rejectHandle(data) {
				this.handleApproval(data);
			},
			handleApproval(data) {
				const query = {
					...data,
					formData: this.formData,
					enCode: this.config.enCode,
				};
				const approvalMethod = data.eventType === "audit" ? Audit : Reject;
				// approvalMethod(this.config.taskId, query).then(res => {
				// 	this.toastAndBack(res.msg, true)
				// })
				if (this.Length === 1) {
					approvalMethod(this.config.taskId, query).then((res) => {
						// this.toastAndBack(res.msg, true)
						// uni.navigateBack()
						uni.switchTab({
							url: "/pages/index/workFlow",
						});
					});
				} else {
					approvalMethod(this.config.taskId, query).then((res) => {
						uni.showToast({
							title: res.msg,
						});
						let data = this.findObjectInfo(this.nextObject, this.comList);
						this.Object = data.currentObject;
						this.Index = data.currentObjectIndex;
						this.nextObjectIndex = data.nextObjectIndex;
						this.nextObject = data.nextObject;
						this.config.taskId = this.Object.taskId;
						if (data.nextObject == "为空") {
							console.log("为空");
							this.nextObject = this.Object;
							this.LastStatus++;
							if (this.LastStatus > 1) {
								setTimeout(() => {
									// uni.navigateBack()
									uni.switchTab({
										url: "/pages/index/workFlow",
									});
								}, 1000);
								this.LastStatus = 0;
								return;
							}
						}
						this.config = {
							flowId: this.Object.flowId,
							formType: this.Object.formType,
							status: this.Object.status,
							fullName: this.Object.fullName,
							id: this.Object.processId,
							taskNodeId: this.Object.thisStepId,
							taskId: this.Object.id,
							opType: 1,
							enCode: this.Object.flowCode,
						};
						this.getBeforeInfo(this.config);
					});
				}
			},
			setBtnLoad(val) {
				this.btnLoading = !!val;
			},
			toastAndBack(title, refresh) {
				uni.showToast({
					title: title,
					complete: () => {
						setTimeout(() => {
							if (refresh) uni.$emit("refresh");
							uni.navigateBack();
						}, 1500);
					},
				});
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #f0f2f6;
		height: 100%;
	}

	.flowBefore-v {
		display: flex;
		flex-direction: column;

		.workFlowTitle {
			width: 100%;
			padding: 0 32rpx 32rpx 32rpx;
			background-color: #ffffff;
			font-size: 32rpx;
			font-weight: 700;
			white-space: pre-wrap;
			text-align: left;
		}

		.flowBefore-box {
			height: 100%;
			flex: 1;
			display: flex;
			flex-direction: column;
			overflow: hidden;
			padding-bottom: 100rpx;

			.discuss_box {

				// border: 1px solid red;
				.discuss_list {
					margin-bottom: 40rpx;

					.discuss_txt {
						width: 100%;
						justify-content: space-between;

						.discuss_txt_left {
							.uName {
								margin-left: 20rpx;
							}
						}

						.del {
							color: red;
						}
					}

					.discuss_content {
						padding-left: 110rpx;

						.txt {
							color: #666666;
						}

						.img_box {
							margin: 40rpx 0;
						}
					}
				}
			}
		}

		.swiper-box {
			height: 100vh;
		}

		.swiper-item {
			flex: 1;
			flex-direction: row;
		}

		.scroll-v {
			flex: 1;
			/* #ifndef MP-ALIPAY */
			flex-direction: column;
			/* #endif */
			width: 100%;
			height: 100%;
		}

		.flowStatus {
			position: absolute;
			top: 90rpx;
			right: 0;
			border: 0;
			margin: 20rpx;
			opacity: 0.7;
			z-index: 9;

			image {
				width: 200rpx;
			}
		}

		.discuss_btn {
			background-color: #fff;
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			// height: 88rpx;
			// box-shadow: 0 -2rpx 8rpx #e1e5ec;
			z-index: 20;

			.custom-style {
				background-color: #2979ff;
				color: #ffffff;
				width: 100%;
				border-radius: 0 !important;

				&::after {
					border: none !important;
				}
			}

			.content {
				padding: 24rpx;
				text-align: center;

				.confrim-btn {
					display: flex;
					flex-direction: row;

					.send {
						flex: 1;
						background-color: #2979ff;
						color: #ffffff;
					}

					.cancel {
						flex: 1;
					}
				}
			}
		}
	}

	.nodeList-v,
	.record-v {
		padding: 32rpx 32rpx 10rpx;
		background-color: #fff;
	}

	.record2-v {
		padding: 0rpx 32rpx 10rpx;
		background-color: #fff;
	}
</style>